<%@ page contentType="text/html;charset=UTF-8" %>

<html>
<head>
	<title>钱包用户管理</title>
	 <%@ include file="/common/meta.jsp" %>
	<%@ include file="/common/import.jsp" %>
	<script type="text/javascript">
	
		$(function(){
			$('#dataList').datagrid({
				title:'钱包用户列表',
				url:'${ctx}/funds/admin/userList.action?ff='+new Date().getTime(),
				striped: true,
				collapsible:false,				
				fitColumns: true,
				pagination:true,
				singleSelect:true,
				rownumbers:true,
				remoteSort: false,
				pageList:[10,15,20,30],
				idField:'userid',
				columns:[[
						{field:'userid', title:'ID',width:50,sortable:false,hidden:true},
						{field:'username',title:'资金账号',width:80,sortable:false},
						{field:'realname',title:'单位/用户名',width:300,sortable:false},
						{field:'certitype',title:'证件类型',width:80,sortable:false,
						   formatter: function(val, rec,rowIndex){
								if(val=='A')return '身份证';
								if(val=='P')return '组织代码';
								if(val=='O')return '信用代码';
								if(val=='Z')return '其他';
							    else return val;
						    }
						},
						{field:'certificate',title:'证件号码',width:140,sortable:false},
						//{field:'bankaccount',title:'银行账户',width:150,sortable:false},
						{field:'contactuser',title:'联系人',width:50,sortable:false},
						{field:'mobile',title:'手机',width:85,sortable:false},
						{field:'createtime',title:'创建日期',width:135,sortable:false}
						/**
						2016-06-06 add xhe 不能再j基礎平台操作，可以查询，但是操作得在业务系统，否则缓存不同步,
						{field:'opt',title:'操作',width:120,sortable:true,
							formatter:function(value,row,index){
								var str = "<a href='javascript:void(0);'   onclick=\"viewYeWin('"+row.username+"');\">查看余额</a>";
								str +=" | <a href='javascript:void(0);'onclick=\"openInWin('"+row.username+"','"+row.realname+"')\">充值</a>";
								return 	str;
							}
						}**/	
				]]
			});
		});
			
		// 刷新列表
		function reload(){
			$('#dataList').datagrid('reload');
		}

		//新的查询功能
		function searchUserNew(){	
			$('#dataList').datagrid('options').pageNumber=parseInt("1"); 
	    	var queryParams = $('#dataList').datagrid('options').queryParams;	       
	        queryParams.username = $('#username').val();
	        queryParams.realname = $('#realname').val();
	        var options = $('#dataList').datagrid('getPager').data("pagination").options;  
	        options.pageNumber=1;  
	        options.total=0;  
	        options.pageSize=10; 
	        $('#dataList').datagrid("reload");
		}
		
		function clearSearch(){					
			 $('#realname').val('');
			 $('#username').val('');
		}  
		function format(num){
			if(num == '' || num == undefined || num == null){
				return '--';
			}
			num = num.toString().replace(/\$|\,/g,'');  
		    if(isNaN(num))num = "0";  
		    sign = (num == (num = Math.abs(num)));  
		    num = Math.floor(num*100+0.50000000001);  
		    cents = num%100;  
		    num = Math.floor(num/100).toString();  
		    if(cents<10)  
		    cents = "0" + cents;  
		    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)  
		    num = num.substring(0,num.length-(4*i+3))+','+  
		    num.substring(num.length-(4*i+3));  
		    return (((sign)?'':'-') + num + '.' + cents); 
		}
		
		function viewYeWin(username){
			var forUrl = "${ctx}/funds/admin/queryYe.action?userEname="+username+"&f="+new Date().getTime();
			var hst = "";
			$.ajax({
				   type:'get',url:forUrl,dataType:'json',
				   success: function(myData){
					   var obj = myData.funds;
					   if(myData.isok=="T"&&obj!=null){
						   hst+="<b>资金账号：</b>"+obj.userId;
						   hst+="<br/><b>总　　额：</b>￥"+format((obj.amtTotal/100).toFixed(2))+"（元）";
						   hst+="<br/><b>可用金额：</b>￥"+format((obj.m1/100).toFixed(2))+"（元）";
						   hst+="<br/><b>冻结金额：</b>￥"+format((obj.m2/100).toFixed(2))+"（元）";
						   hst+="<br/><b>可出金额：</b>￥"+format((obj.amtOut/100).toFixed(2))+"（元）";
					   }
					   $("#div_msg").html(hst);
				  }
			});
			$("#infoDetailWin").window('open');
			
		}
		//弹出充值框
		function openInWin(userEname,userCname){
			$("#txt_userEname").val(userEname);
			$("#span_userEname").text(userEname);
			$("#span_userCname").text(userCname);
			$('#inputWindow').dialog('open');
		}
		//提交充值
		function saveIn(){
			var userEname = $("#txt_userEname").val();
			var amount = $("#txt_amount").val();
			if(!userEname){
				alert('充值账号不能为空！');
				return;
			}
			if(!amount){
				alert('充值金额不能为空！');
				return;
			}
			if(!confirm('您确定给【'+userEname+'】充值【'+amount+'】元？')) return false;
			var forUrl = "${ctx}/funds/admin/sendIn.action?userEname="+userEname+"&amount="+amount+"&f="+new Date().getTime();
			$.ajax({
				   type:'get',url:forUrl,dataType:'json',
				   success: function(myData){
						alert(myData.msg);
						window.location.reload();
				  }
			});
		
		}
	</script>
</head>

<!-- 充值框 -->
<div id="inputWindow" class="easyui-dialog" closed="true" title="充值" style="width:580px;height:280px;modal:true;" data-options="jconCls:'icon-save',modal:true">
<form name="addForm" id="addForm" method="post" action="">
<table class="info" cellspacing=1 cellpadding="0">
    <input type="hidden" name="formToken" value=""/>
    <input type="hidden" name="userEname" id="txt_userEname" value=""/>
	<tr>
		<th style="width: 120px;">充值账号</th>
		<td><span id="span_userEname"></span></td>
	</tr>
	<tr>
		<th>单位名称</th>
		<td><span id="span_userCname"></span></td>
	</tr>
	<tr>
		<th>充值金额</th>
		<td>
			<input type="text" id="txt_amount" name="amount" size="10" maxlength="10" class="easyui-numberbox" min='0' validType="length[1,15]" precision="2" />（元）
		</td>
	</tr>
	<!-- <tr>
		<th>银行到账时间</th>
		<td>
			<input id="reachDate" name="createSpaceename" class="easyui-datetimebox" size="22" readonly="readonly" required="true"><font color="red">*</font>
		</td>
	</tr>
	<tr>
		<th>银行流水号</th>
		<td>
			<input id="buyerId" name="buyerId"   size="32" maxlength="50" class="easyui-validatebox"  required="true"><font color="red">*</font>
		</td>
	</tr>
	<tr>
		<th>操作描述</th>
		<td>
			<input type="text" id="proName" name="proName" size="50" maxlength="50" class="easyui-validatebox"  required="true"/><font color="red">*</font>
		</td>
	</tr>
	<tr>
		<th>附件材料</th>
		<td>
			<div msg="第1组">
			  <img alt="" id="imgAttaUrl" style="display:;" src="" width="100" height="60"/>
			  <label onclick="addUploadFile(1);" for="uploadFileInput" class="fDef_Btn" >选择图片</label>
			  <label id="fileUpText_1_subbtn" onclick="$.toolsupload.uploadSubmit(this);" style='display:none;' class="fDef_Btnse" >开始上传</label>
			  <input id="fileUpText_1" name="applyTypeDesc" type="hidden" class="fDef_Input" >
			</div>
		</td>
	</tr> -->
  </table>
  <center><a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-add"  onClick="saveIn();">提交</a></center>
</form>
</div>
<body>
	<form action="" name ="searchForm" id="searchForm">
		<table class="planel-body">
				<tr>
					<td>用户名称</td>
					<td>
						<input id="realname" name="realname" maxlength="50" value=""/>
					</td>
					<td>资金账号</td>
					<td>
						<input id="username" name="username" maxlength="20" value=""/>
					</td>
					<td>
						<a class="easyui-linkbutton" iconCls="icon-search"
							onclick="searchUserNew();">查询</a>
						<a class="easyui-linkbutton" iconCls="" onclick="clearSearch();">清空</a>
					</td>
				</tr>
			</table>
	</form>		
	<!-- 应用列表 -->
	<table id="dataList"></table>
	
    <div id="infoDetailWin"  class="easyui-window" title="查看余额"  style="padding:2px;width:350px;height:220px;"
		iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
		<div id="div_msg" style="padding: 10px;line-height:30px;padding-left:50px;"></div>
    </div>
</body>
</html>